﻿
using OABLL;
using OAModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyOA
{
    /// <summary>
    /// 请假理由
    /// </summary>
    public partial class QingJiaGuanLi : Form 
    {
        public event Save OnSave;//定义委托
        public delegate void Save();//定义事件

        qingjiabll bll = new qingjiabll();
        public string _yuangongid = string.Empty;
        public QingJiaGuanLi(string oa)
        {
            InitializeComponent();
            this._yuangongid = oa;
        }

        private void btn请假提交_Click(object sender, EventArgs e)
        {
            Random dh = new Random();
            QijiaEntity qj = new QijiaEntity();

        
            qj.Oa员工id = lbl员工id.Text;
            qj.Oa请假单号 = dh.Next(10000, 9999999).ToString();
            qj.Oa员工姓名 = lblxm.Text;
            //在代码获取日期前添加此代码 设置日期格式 然后new DateTime 完美解决
            CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd HH:mm:ss";
            culture.DateTimeFormat.LongTimePattern = ""; Thread.CurrentThread.CurrentCulture = culture;
            qj.Oa请假时间 = DateTime.Parse(dt请假时间.Value.ToString());
            qj.Oa请假时长 = tx请假时长.Text.Trim();
            //if (tx请假时长.Text != null)
             //   MessageBox.Show("提交数据，不能为空！");
           // qj.Oa请假时长 = tx请假时长.Text.Trim();
            qj.Oa请假理由 = textBox1.Text.Trim();
           // if (tx请假时长.Text != null)
            //    MessageBox.Show("提交数据，不能为空！");
           // qj.Oa请假理由 = textBox1.Text.Trim();


            bool b1 = bll.Addqingjia(qj);
            if (b1 == true)
            {
                MessageBox.Show("提交申请成功，等待审批中！");
               
                this.Close();
                OnSave(); //关闭的时候执行事件

            }
            else
            {
                MessageBox.Show("提交失败，请稍后重试！");
            }
            this.Close();
        }



        //页面加载数据
        private void QingJiaGuanLi_Load(object sender, EventArgs e)
        {
            OAUseEntity user = new OAUseBLL().Getyuangong(_yuangongid);
            this.lbl员工id.Text = _yuangongid;
            this.lblxm.Text = user.Oa姓名;
        }
        /// <summary>
        /// 不能提交空数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tx请假时长_TextChanged(object sender, EventArgs e)
        {
            

        }
        /// <summary>
        /// 不能提交空数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
        }
    }
    }
    
